// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/base/api/EventInfoApi'

import OneClass from '@api/base/model/EventInfoReq'
import BaseClass from '@api/base/model/EventInfoDto'
import MemberClass from '@api/base/model/EventMemberDto'
import SupplyClass from '@api/base/model/EventSupplyDto'
// import FileClass from '@api/base/model/FileInfoDto'

const SubmitClass = OneClass
const PassClass = OneClass
const RejClass = OneClass

const CLIENT = CORE.grpcCLIENT(Client)
const BASE = [BaseClass, 'dto']

const MEMBER = [MemberClass, 'eventMemberDtos', 1]
const SUPPLY = [SupplyClass, 'eventSupplyDtos', 1]
// const FILE = [FileClass, 'fileInfoDtos', 1]
const EDIT = [...BASE, null, (dto, obj) => CORE.grpcDTO(dto, obj, MEMBER, SUPPLY)]

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 单项 —————————————————————————————— //

  validOne(one) {
    return one.id
  },
  async getOne({ id }, TIP = '查询详情') {
    const DTO = CORE.grpcDTO(OneClass, { id }, BASE)
    const resp = await CORE.grpc(TIP, CLIENT, 'eventInfoDetailQuery', DTO)
    return resp.dto || {}
  },
  transOne(obj) {
    const fileList = obj.fileInfoDtos || []
    obj.imageList = fileList.filter((item) => item.fileType === 1)
    obj.videoList = fileList.filter((item) => item.fileType === 3)
    obj.duringText = CORE.numDuringTwo((obj.handleDuration / 1000) | 0)
    return obj
  },

  // —————————————————————————————— 提交 —————————————————————————————— //

  async submit(one, TIP = '提交') {
    const DTO = CORE.grpcDTO(SubmitClass, { ...one, handleStatus: 2 }, EDIT)
    await CORE.grpc(TIP, CLIENT, 'eventInfoHandler', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 通过 —————————————————————————————— //

  async pass({ id }, TIP = '通过') {
    const DTO = CORE.grpcDTO(PassClass, { id, handleStatus: 3 }, BASE)
    await CORE.grpc(TIP, CLIENT, 'eventInfoHandler', DTO)
    return ''
  },

  // —————————————————————————————— 拒绝 —————————————————————————————— //

  async rej({ id }, TIP = '拒绝') {
    const DTO = CORE.grpcDTO(RejClass, { id, handleStatus: 4 }, BASE)
    await CORE.grpc(TIP, CLIENT, 'eventInfoHandler', DTO)
    return CORE.grpcOK(TIP)
  },
}
